package com.cskaoyan.order.service.remote;

import com.cskaoyan.mall.order.dto.StockDto;
import com.cskaoyan.mall.order.service.StockService;
import com.cskaoyan.order.dal.entitys.Stock;
import com.cskaoyan.order.dal.persistence.StockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Charadic
 * @since 2022/05/21 14:22
 */
@RestController
public class StockServiceImpl implements StockService {
    @Autowired
    StockMapper stockMapper;

    @Override
    @GetMapping("/rpc/getItemStock")
    public StockDto getItemStock(Long itemId) {
        Stock stock = stockMapper.selectStock(itemId);
        StockDto stockDto = new StockDto();
        stockDto.setItemId(stock.getItemId());
        stockDto.setStockCount(stock.getStockCount());
        stockDto.setLockCount(stock.getLockCount());
        stockDto.setRestrictCount(stock.getRestrictCount());
        return stockDto;
    }
}
